package org.dromara.web.controller.platform;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.dromara.platform.domain.bo.BatchTMiniProgramCategoryBo;
import org.dromara.platform.domain.vo.MiniProgramCategorySelectVo;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.platform.domain.vo.TMiniProgramCategoryVo;
import org.dromara.platform.domain.bo.TMiniProgramCategoryBo;
import org.dromara.platform.service.ITMiniProgramCategoryService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 小程序类目信息
 *
 * @author Lion Li
 * @date 2025-06-11
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/platform/miniProgramCategory")
public class TMiniProgramCategoryController extends BaseController {

    private final ITMiniProgramCategoryService tMiniProgramCategoryService;

    /**
     * 查询小程序类目信息列表
     */
    @SaCheckPermission("platform:miniProgramCategory:list")
    @GetMapping("/list")
    public TableDataInfo<TMiniProgramCategoryVo> list(TMiniProgramCategoryBo bo, PageQuery pageQuery) {
        return tMiniProgramCategoryService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出小程序类目信息列表
     */
    @SaCheckPermission("platform:miniProgramCategory:export")
    @Log(title = "小程序类目信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(TMiniProgramCategoryBo bo, HttpServletResponse response) {
        List<TMiniProgramCategoryVo> list = tMiniProgramCategoryService.queryList(bo);
        ExcelUtil.exportExcel(list, "小程序类目信息", TMiniProgramCategoryVo.class, response);
    }

    /**
     * 获取小程序类目信息详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("platform:miniProgramCategory:query")
    @GetMapping("/{id}")
    public R<TMiniProgramCategoryVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(tMiniProgramCategoryService.queryById(id));
    }

    /**
     * 新增小程序类目信息
     */
    @SaCheckPermission("platform:miniProgramCategory:add")
    @Log(title = "小程序类目信息", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody TMiniProgramCategoryBo bo) {
        return toAjax(tMiniProgramCategoryService.insertByBo(bo));
    }

    /**
     * 修改小程序类目信息
     */
    @SaCheckPermission("platform:miniProgramCategory:edit")
    @Log(title = "小程序类目信息", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody TMiniProgramCategoryBo bo) {
        return toAjax(tMiniProgramCategoryService.updateByBo(bo));
    }

    /**
     * 删除小程序类目信息
     *
     * @param ids 主键串
     */
    @SaCheckPermission("platform:miniProgramCategory:remove")
    @Log(title = "小程序类目信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(tMiniProgramCategoryService.deleteWithValidByIds(List.of(ids), true));
    }

    /**
     * 微信类目查询
     */
    @SaCheckPermission("platform:miniProgramCategory:query")
    @GetMapping("/wxCategorySelect")
    public R<List<MiniProgramCategorySelectVo>> wxCategorySelect(@RequestParam("baseId") Long baseId) {
        return R.ok(tMiniProgramCategoryService.wxCategorySelect(baseId));
    }

    /**
     * 批量修改类目
     * @param batchTMiniProgramCategoryBo
     */
    @SaCheckPermission("platform:miniProgramCategory:edit")
    @Log(title = "小程序类目信息", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PostMapping("/batchUpdateCategory")
    public R batchUpdateCategory(@RequestBody BatchTMiniProgramCategoryBo batchTMiniProgramCategoryBo) {
        return tMiniProgramCategoryService.batchUpdateCategory(batchTMiniProgramCategoryBo);
    }


}
